package com.example.cloudpracticeplatform.mapper;

import com.example.cloudpracticeplatform.entity.Course;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CourseMapper {
    @Insert("INSERT INTO courses(teacher_id, name, duration, level, description, image_path, guide_path) " +
            "VALUES(#{teacherId}, #{name}, #{duration}, #{level}, #{description}, #{imagePath}, #{guidePath})")
    @Options(useGeneratedKeys = true, keyProperty = "courseId")
    int insert(Course course);

    @Update("UPDATE courses SET teacher_id=#{teacherId}, name=#{name}, duration=#{duration}, level=#{level}, " +
            "description=#{description}, image_path=#{imagePath}, guide_path=#{guidePath} WHERE course_id=#{courseId}")
    int update(Course course);

    @Delete("DELETE FROM courses WHERE course_id=#{courseId}")
    int delete(Integer courseId);

    @Select("SELECT * FROM courses WHERE course_id=#{courseId}")
    Course findById(Integer courseId);

    @Select("SELECT * FROM courses LIMIT #{offset}, #{limit}")
    List<Course> findAll(int offset, int limit);
    
    @Update("UPDATE courses SET image_id= #{imageId} WHERE course_id= #{courseId}")
    int updateImageId(Integer courseId, String imageId);
}